package com.tt.vtg.scenario.http.decoder;

import com.tt.vtg.scenario.util.json.JsonUtils;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.nio.charset.Charset;

/*
* It is a inbound handler.
* */
public abstract class AbstractHttpJsonDecoder<T, CLZ> extends MessageToMessageDecoder<T> {
    private Class<CLZ> clz;
    protected final static Charset UTF_8 = Charset.forName("utf-8");

    protected AbstractHttpJsonDecoder(Class<CLZ> clz) {
        this.clz = clz;
    }

    protected CLZ _decode(ByteBuf content){
        return JsonUtils.toObj(content.toString(UTF_8), clz);
    }
}
